home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / laptop-mode-tools / modules / start-stop-programs < prev    next >
Encoding:
Text File  |  2012-05-20  |  3.7 KB  |  126 lines

  1. #! /bin/sh
  2. #
  3. # Laptop mode tools module: start and stop programs
  4. #
  5.  
  6. if [ x$CONTROL_START_STOP = x1 ] ; then
  7.    #
  8.    # Undo the previous state.
  9.    #
  10.    if [ -f /var/run/laptop-mode-tools/start-stop-undo-actions ] ; then
  11.     cat /var/run/laptop-mode-tools/start-stop-undo-actions | \
  12.         while read SCRIPT STARTSTOPACTION ; do
  13.             $SCRIPT $STARTSTOPACTION
  14.         done
  15.    fi
  16.  
  17.    #
  18.    # Apply the new state, if LMT is enabled.
  19.    #
  20.    if [ "$STATE" = "enabled" ]; then
  21.     # Empty undo file first. We write the actions we take
  22.     # into this file, so that we can undo them at the
  23.     # next state change. Note: we actually
  24.     # write the actions to the file in reverse order,
  25.     # so we can execute the commands easily afterwards.
  26.     echo > /var/run/laptop-mode-tools/start-stop-undo-actions 
  27.         
  28.        
  29.     if [ $ON_AC -eq 1 ] ; then
  30.         if [ "$ACTIVATE" -eq 1 ] ; then        
  31.             START_STOP_DIR_PREFIX=/etc/laptop-mode/lm-ac
  32.             START_SERVICES="$LM_AC_START"
  33.             STOP_SERVICES="$LM_AC_STOP"            
  34.         else
  35.             START_STOP_DIR_PREFIX=/etc/laptop-mode/nolm-ac
  36.             START_SERVICES="$NOLM_AC_START"
  37.             STOP_SERVICES="$NOLM_AC_STOP"            
  38.         fi
  39.     else
  40.         START_STOP_DIR_PREFIX=/etc/laptop-mode/batt
  41.         START_SERVICES="$BATT_START"
  42.         STOP_SERVICES="$BATT_STOP"
  43.     fi
  44.     START_DIR="$START_STOP_DIR_PREFIX"-start
  45.     STOP_DIR="$START_STOP_DIR_PREFIX"-stop
  46.     if [ -d "$STOP_DIR" ] ; then
  47.         for SCRIPT in "$STOP_DIR"/* ; do
  48.             if [ -e "$SCRIPT" ] ; then
  49.                 log "VERBOSE" "Stopping $SCRIPT"
  50.                 "$SCRIPT" stop
  51.                 # Dereference any links. When people configure
  52.                 # the directories with links and then they remove
  53.                 # links while laptop mode is active, the "undo"
  54.                 # will fail if we don't dereference the links
  55.                 # before storing them.
  56.                 LINKTARGET=`readlink -f "$SCRIPT"`
  57.                 sed -i "1i $LINKTARGET start" /var/run/laptop-mode-tools/start-stop-undo-actions
  58.             fi
  59.         done
  60.     fi
  61.     if [ -d "$START_DIR" ] ; then
  62.         for SCRIPT in "$START_DIR"/* ; do
  63.             if [ -e "$SCRIPT" ] ; then
  64.                 log "VERBOSE" "Starting $SCRIPT"
  65.                 "$SCRIPT" start
  66.                 LINKTARGET=`readlink -f "$SCRIPT"`
  67.                 sed -i "1i $LINKTARGET stop" /var/run/laptop-mode-tools/start-stop-undo-actions
  68.             fi
  69.         done
  70.     fi
  71.  
  72.  
  73.     log "VERBOSE" "START_SERVICES = $START_SERVICES"
  74.     log "VERBOSE" "STOP_SERVICES = $STOP_SERVICES"
  75.     if [ "$START_SERVICES" != "" -o "$STOP_SERVICES" != "" ] ; then
  76.         log "MSG" "Starting/stopping services"
  77.     
  78.         # Determine how we can start/restart services.
  79.         if ( which invoke-rc.d > /dev/null ) ; then
  80.             # Debian uses invoke-rc.d
  81.             RCPROG="invoke-rc.d "
  82.             INITSCRIPT=laptop-mode
  83.         elif ( which service > /dev/null ) ; then
  84.             # RedHat uses service
  85.             RCPROG="service "
  86.             INITSCRIPT=laptop-mode
  87.         else
  88.             # Any other -- we start the init script it ourselves.
  89.  
  90.             # Try non-link directories first, then try links. This helps if one of
  91.             # the locations is linked to another, which is the case on some distros.
  92.             if [ -d /etc/rc.d/init.d -a ! -L /etc/rc.d/init.d ] ; then
  93.                 INIT_D=/etc/rc.d/init.d
  94.             elif [ -d /etc/rc.d -a ! -L /etc/rc.d -a ! -d /etc/rc.d/init.d ] ; then
  95.                 INIT_D=/etc/rc.d
  96.             elif [ -d /etc/init.d -a ! -L /etc/init.d ] ; then
  97.                 INIT_D=/etc/init.d
  98.             elif [ -d /etc/rc.d/init.d ] ; then
  99.                 INIT_D=/etc/rc.d/init.d
  100.             elif [ -d /etc/rc.d ] ; then
  101.                 INIT_D=/etc/rc.d
  102.             elif [ -d /etc/init.d ] ; then
  103.                 INIT_D=/etc/init.d
  104.             else
  105.                 log "ERR" "Cannot determine location of init scripts."
  106.                 exit 1
  107.             fi
  108.  
  109.             RCPROG="$INIT_D/"
  110.         fi
  111.  
  112.         for SERVICE in $STOP_SERVICES ; do
  113.             log "VERBOSE" "Stopping service $SERVICE."
  114.             $RCPROG$SERVICE stop
  115.             sed -i "1i $RCPROG$SERVICE start" /var/run/laptop-mode-tools/start-stop-undo-actions
  116.         done
  117.         for SERVICE in $START_SERVICES ; do
  118.             log "VERBOSE" "Starting service $SERVICE."
  119.             $RCPROG$SERVICE start
  120.             sed -i "1i $RCPROG$SERVICE stop" /var/run/laptop-mode-tools/start-stop-undo-actions
  121.         done
  122.     fi
  123.    fi
  124. fi
  125.  
  126.